import {getActionSimple, postActionSimple} from "../util/api";
import LocalStorageConstant from "@/constant/LocalStorageConstant";
import {UniStorage} from "@/util/uniUtils";

/**
 * 公共API
 */
export default class DictApi{
    static url={
        queryDictItemsByCode:'/api/common/queryDictItemsByCode',
        queryDictAll:'/api/common/queryDictAll',
        getCategoryDictAll:'/api/common/queryAllCategoryDict',
        getAsyncTreeByCode:'/api/common/getAsyncTreeByCode',
        getAsyncTreeById:'/api/common/getAsyncTreeById',
    }

    /**
     * 获取数据字典
     * @param params
     * @returns
     */
    static async getDictItemsByCode(params){
        return await getActionSimple(this.url.queryDictItemsByCode,params)
    }
    /**
     * 获取所有数据字典
     * @param params
     * @returns
     */
    static async getDictAll(params){
        return await getActionSimple(this.url.queryDictAll,params)
    }

    /**
     * 获取数据字典列表，分类字典列表
     * @param commit
     * @returns {Promise<void>}
     */
    static async getDict(){
        //获取数据字典列表,分类字典列表
        let [dictList,categoryList] = await Promise.all([this.getDictAll(),this.getCategoryDictAll()])
        UniStorage.set(LocalStorageConstant.DICT_LIST,dictList)
        UniStorage.set(LocalStorageConstant.CATEGORY_LIST,categoryList)
    }
    /**
     * 获取所有分类字典
     * @param params
     * @returns
     */
    static async getCategoryDictAll(params){
        return await getActionSimple(this.url.getCategoryDictAll,params)
    }
    /**
     * 异步树查询，根据父code异步树查询一定状态下的子节点
     *
     * @param status     1 查询所有未禁用状态，0 查询禁用状态，null 所有数据
     * @param parentCode null 查询所有根节点，不为null 查询其子节点
     * @return
     */
    static async getAsyncTreeByCode(params){
        return await getActionSimple(this.url.getAsyncTreeByCode,params)
    }
    /**
     * 异步树查询，根据父id异步树查询一定状态下的子节点
     *
     * @param keyword 查询关键字
     * @param pId     父节点id
     * @param isAll   是否查询所有，默认true，false，只查询非禁用
     * @return
     */
    static async getAsyncTreeById(params){
        return await getActionSimple(this.url.getAsyncTreeById,params)
    }

}
